connection mySQL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have following code to connect MySQL server.
I got Connected to database message, but I got Could not run query : No database selected error message when run mysql_query. I check that the database name is correct, I use root account which should have the rights to do select. I can access my db using phpMyAdmin, so my PHP and MySQL server both running.

It seems that it connected to MySQL, but for some reason it does not connect to the database.

Are there any configuration need to check for the connection?
Your help and information is great appreciated,


$hostname = "localhost";
$username = "MyUser";
$password = "mypassword";

try {
$dbh = new PDO("mysql:host=localhost;dbname=mydb;charset=utf8", $username, $password);
      echo "Connected to database";
    }
catch(PDOException $e)
   {
   echo $e->getMessage();
    }


$result = mysql_query("SELECT invid, invdate, note, amount FROM invheader");
if (!$result) {
   echo 'Could not run query: ' . mysql_error();
   exit;
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux