Jump to content

.vbs vs. .php - PLEASE HELP


JSHINER

Recommended Posts

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!

Link to comment
Share on other sites

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);

?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.