jlgray48 Posted April 22, 2007 Share Posted April 22, 2007 I have WAMP installed and all appears to be working fine but when I try to execute a sql command from php it does nothing. I need help..... Here is my code..... <? mysql_connect("127.0.0.1"); mysql_select_db("uah") or die( "Unable to select database"); $sql="create table yahoo(id int, name char(10), primary key(id));"; mysql_query($sql,$conn); ?> Any help is greatly appreciated. I'm new so go easy on me. Link to comment https://forums.phpfreaks.com/topic/48096-solved-how-to-know-if-you-are-connected-to-mysql-within-php-script/ Share on other sites More sharing options...
AndyB Posted April 22, 2007 Share Posted April 22, 2007 Where's $conn defined? mysql_connect expects a hostname, username, password - hostname is usually localhost Link to comment https://forums.phpfreaks.com/topic/48096-solved-how-to-know-if-you-are-connected-to-mysql-within-php-script/#findComment-235055 Share on other sites More sharing options...
jlgray48 Posted April 22, 2007 Author Share Posted April 22, 2007 Left that out, it is in my code...... $conn = mysql_connect("localhost","jlgray48","peanut99"); mysql_select_db("uah") or die( "Unable to select database"); $sql="create table yahoo(id int, name char(10), primary key(id));"; mysql_query($sql,$conn); Link to comment https://forums.phpfreaks.com/topic/48096-solved-how-to-know-if-you-are-connected-to-mysql-within-php-script/#findComment-235056 Share on other sites More sharing options...
shaymol Posted April 22, 2007 Share Posted April 22, 2007 Hi friend You your code mysql_connect method needs 3 param as hostname, username n password. You can try with the following code . i think it must works. $link = mysql_connect("localhost", "mysql_user", "mysql_password"); mysql_select_db("database", $link); $result = mysql_query("create table yahoo(id int, name char(10), primary key(id))", $link); if($result) { echo 'Successfully created'; } else { echo 'Could not create '; } Link to comment https://forums.phpfreaks.com/topic/48096-solved-how-to-know-if-you-are-connected-to-mysql-within-php-script/#findComment-235057 Share on other sites More sharing options...
jlgray48 Posted April 22, 2007 Author Share Posted April 22, 2007 Still nothing, Blank page. I think I would feel better if it gave me an error in my php code. Link to comment https://forums.phpfreaks.com/topic/48096-solved-how-to-know-if-you-are-connected-to-mysql-within-php-script/#findComment-235059 Share on other sites More sharing options...
shaymol Posted April 22, 2007 Share Posted April 22, 2007 hi jlgray it would be better if you show your modified code again. thanks ShaymoL Link to comment https://forums.phpfreaks.com/topic/48096-solved-how-to-know-if-you-are-connected-to-mysql-within-php-script/#findComment-235065 Share on other sites More sharing options...
Jaquio Posted April 22, 2007 Share Posted April 22, 2007 [/code] <?php //MySQL information MODIFY IT HERE. $host = "";//Host $db_name = "";//Database $db_user = "";//Username $db_password = "";//Password //Connect to the database $dbnews = @mysql_connect("$host", "$db_user", "$db_password"); if (!$dbnews) { die(" <center>Could not connect to MySQL Server($host). <br>" . mysql_error() . "</center> "); } //Select the database if (!@mysql_select_db("$db_name")) { die(" <center>Could not select MySQL Database($db_name)<br>" . mysql_error () . "</center> "); } mysql_query("create table yahoo(id int, name char(10), primary key(id))", $link); ?> Try that and see how it works out. Link to comment https://forums.phpfreaks.com/topic/48096-solved-how-to-know-if-you-are-connected-to-mysql-within-php-script/#findComment-235113 Share on other sites More sharing options...
jlgray48 Posted April 22, 2007 Author Share Posted April 22, 2007 Here is the error I get when I ran this code..... When I start mysql from windows or the cmd prompt it doesn't ask me for my username and password. Where does it pull the @localhost part from on my user? Could not connect to MySQL Server(127.0.0.1). Access denied for user: 'jlgray48@localhost' (Using password: YES) <?php //MySQL information MODIFY IT HERE. $host = "127.0.0.1";//Host $db_name = "uah";//Database $db_user = "jlgray48";//Username $db_password = "peanut99";//Password //Connect to the database $dbnews = @mysql_connect("$host", "$db_user", "$db_password"); if (!$dbnews) { die(" <center>Could not connect to MySQL Server($host). " . mysql_error() . "</center> "); } //Select the database if (!@mysql_select_db("$db_name")) { die(" <center>Could not select MySQL Database($db_name) " . mysql_error () . "</center> "); } mysql_query("create table yahoo(id int, name char(10), primary key(id))", $link); ?> Link to comment https://forums.phpfreaks.com/topic/48096-solved-how-to-know-if-you-are-connected-to-mysql-within-php-script/#findComment-235162 Share on other sites More sharing options...
shaymol Posted April 23, 2007 Share Posted April 23, 2007 Hi mates according to your code i have a question to u that is can you connect to your mysql server from command promt using those credentials (userName : jlgray48 pswd: peanut99) if you can connect with those credentials then you can also connect from the php but as you cannot connect with the credentials you can try with your mysql root user Thanks ShaymoL Link to comment https://forums.phpfreaks.com/topic/48096-solved-how-to-know-if-you-are-connected-to-mysql-within-php-script/#findComment-235739 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.