JSHINER Posted March 27, 2007 Share Posted March 27, 2007 I was given the following code as a "sample" to connect for a project. Only problem is its VB and the site is in PHP - does anyone know what this would translate to in PHP? dim conn, rs, username, password username = "MyId" password = "MyPass" set conn = createobject("ADODB.Connection") conn.open "Provider=SQLOLEDB; Data Source=sub.site.com,7978; Initial Catalog=vow;User ID=" & username & "; Password=" & password sql = "select * from View_Towns with (nolock) where Number = 1" set rs=conn.execute(sql) do until rs.EOF msgbox("Successfully Connected") rs.movenext loop set rs = nothing conn.close set conn = nothing Any help would be much appreciated. I'm pretty new to PHP and getting the hang of it - but VB is a foreign language to me. Thanks in advance for any help! Quote Link to comment https://forums.phpfreaks.com/topic/44529-vbs-vs-php-please-help/ Share on other sites More sharing options...
wildteen88 Posted March 27, 2007 Share Posted March 27, 2007 I don't understand VB either however the converted code will be like this: <?php // Database credentials $user = 'MyId'; $pass = 'MyPass'; $conn = mysql_connect('localhost', $user, $pass); mysql_select_db('database_name_here', $conn); /* I couldn't see what database the VB code was using. If you know it replace 'database_name_here' with the actual database name */ $sql = 'SELECT * FROM View_Towns WHERE Number = 1'; $result = mysql_query($sql, $conn); if(mysql_num_rows($result) > 0) { echo 'Results found!'; } else { echo 'No results found!'; } mysql_close($conn); ?> Quote Link to comment https://forums.phpfreaks.com/topic/44529-vbs-vs-php-please-help/#findComment-216281 Share on other sites More sharing options...
JSHINER Posted March 27, 2007 Author Share Posted March 27, 2007 How do I connect to another site via port # ____ - instead of localhost. Example: sub.site.com port 7070 Quote Link to comment https://forums.phpfreaks.com/topic/44529-vbs-vs-php-please-help/#findComment-216286 Share on other sites More sharing options...
wildteen88 Posted March 27, 2007 Share Posted March 27, 2007 change localhost in mysql_connect function to sub.mysite.com:3306 where 3306 is change it to the port number sub.site.com's database runs on. Quote Link to comment https://forums.phpfreaks.com/topic/44529-vbs-vs-php-please-help/#findComment-216289 Share on other sites More sharing options...
JSHINER Posted March 27, 2007 Author Share Posted March 27, 2007 When I do sub.mysite.com:3306 it gives me: "Warning: mysql_connect(): Lost connection to MySQL server during query in..." When I do sub.mysite.com3306 ( No : ) it gives me: "Warning: mysql_connect(): Access denied for user 'username'@'IP' (using password: YES) in..." Neither is a desirable result - however the "Access denied" leads me to belive it did in fact connect, but I do not have access. Is this correct? Quote Link to comment https://forums.phpfreaks.com/topic/44529-vbs-vs-php-please-help/#findComment-216291 Share on other sites More sharing options...
JSHINER Posted March 27, 2007 Author Share Posted March 27, 2007 I also noticed in the first example - they have: "User ID=" & username & "; Password=" & password" - Do I need to set that in my mysql_connect ? Quote Link to comment https://forums.phpfreaks.com/topic/44529-vbs-vs-php-please-help/#findComment-216293 Share on other sites More sharing options...
wildteen88 Posted March 27, 2007 Share Posted March 27, 2007 the mysql_connect function is for connecting to a mysql database Does your site use a mysql database? I also noticed in the first example - they have: "User ID=" & username & "; Password=" & password" - Do I need to set that in my mysql_connect ? No as it is sent through the mysql_connect function. Change the values for the $user and $pass variables to that of your database username and password. Quote Link to comment https://forums.phpfreaks.com/topic/44529-vbs-vs-php-please-help/#findComment-216295 Share on other sites More sharing options...
JSHINER Posted March 27, 2007 Author Share Posted March 27, 2007 It is not my site - it is another site I am connecting to. They do use mysql databases. If I am getting Access Denied - that is on their end, correct ? Quote Link to comment https://forums.phpfreaks.com/topic/44529-vbs-vs-php-please-help/#findComment-216297 Share on other sites More sharing options...
wildteen88 Posted March 27, 2007 Share Posted March 27, 2007 It depends. Are you sure you are using the correct username and password to connect to the mysql server? Quote Link to comment https://forums.phpfreaks.com/topic/44529-vbs-vs-php-please-help/#findComment-216300 Share on other sites More sharing options...
JSHINER Posted March 27, 2007 Author Share Posted March 27, 2007 Yes. They provided me with that information so I could access the database. Multiple people have access, each with a different username and password. Quote Link to comment https://forums.phpfreaks.com/topic/44529-vbs-vs-php-please-help/#findComment-216302 Share on other sites More sharing options...
wildteen88 Posted March 27, 2007 Share Posted March 27, 2007 have you confirmed you are using the correct hostname - first parameter of the mysql_connect function. Also if the mysql server is on the same server as the site then you can just use localhost rather than specifying the actual hostname and port. PHP connects to port 3306 by default when connecting to MySQL. Quote Link to comment https://forums.phpfreaks.com/topic/44529-vbs-vs-php-please-help/#findComment-216304 Share on other sites More sharing options...
JSHINER Posted March 27, 2007 Author Share Posted March 27, 2007 Yes I was provided the hostname and port to connect through. It is not on the same server. It's on a completely different server. Quote Link to comment https://forums.phpfreaks.com/topic/44529-vbs-vs-php-please-help/#findComment-216312 Share on other sites More sharing options...
wildteen88 Posted March 28, 2007 Share Posted March 28, 2007 Hold on I think I have over looked something. Looking through the thread I mis read the following post of yours: When I do sub.mysite.com:3306 it gives me: "Warning: mysql_connect(): Lost connection to MySQL server during query in..." When I do sub.mysite.com3306 ( No : ) it gives me: "Warning: mysql_connect(): Access denied for user 'username'@'IP' (using password: YES) in..." Neither is a desirable result - however the "Access denied" leads me to belive it did in fact connect, but I do not have access. Is this correct? The bit that I missed read is highlighted in red. That error message leads me to believe that you connected to mysql, however during the query the connection was lost. Whats the output of the following code: <?php // Database credentials $user = 'MyId'; $pass = 'MyPass'; echo 'Initializing database connection...<br />'; $conn = mysql_connect('localhost', $user, $pass); echo 'Database connection initialized!<br />'; echo 'Attempting to select database for use...<br />'; mysql_select_db('database_name_here', $conn); echo 'Database selected!'; ?> Note if you get any errors post them here in full Quote Link to comment https://forums.phpfreaks.com/topic/44529-vbs-vs-php-please-help/#findComment-216923 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.