Page 1 of 1

Problem with mysql connections

PostPosted: February 7th, 2017, 12:36 am
by Jaood
Today I`ve installed the php tools.
Simple php code worked fine. Then i want to try to retrieve some info from my db.
Then i`ve started my denwer tool pack, that manage apache.
So where is the problem?
Code: Select all
<?php
mysql_connect("localhost","root","") or die("Could not connect: ".mysql_error());
mysql_select_db("mydb");
$sql="SELECT * FROM table1";
$reuslt=mysql_query($sql);
while($row=mysql_fetch_array($reuslt,MYSQL_ASSOC))
{
    echo $row['id'].':'.$row['text']."<br/>";
}
?>

Apache works fine, but every time i try to run this, i get next error
Uncaught Error: Call to undefined function mysql_connect() in D:\GDrive\PHP Projects\PHPWebProject1\PHPWebProject1\index.php:2

Stack trace:

#0 {main}

thrown

How could i fix this?

Re: Problem with mysql connections

PostPosted: February 7th, 2017, 9:07 am
by Miloslav Beno
Hello,

This means mysql extension is not installed in the php framework you are using.

Please check in the project properties, server tab what actual server is used. If you want to use apache you will need to set up Custom server here and fill in the virtual directory of your project. Then it should work fine, assuming mysql is installed in php on your apache.

Thanks!

Re: Problem with mysql connections

PostPosted: February 7th, 2017, 9:56 pm
by jazz
This isn't a PHP Tools issue, but I can help.

Firstly, mysql_connect is part of the php_mysql extension which was deprecated in PHP5.5. You will either need to use MySQLi, or PDO. I would suggest PDO.

I believe the MySQL PDO driver is enabled by default. To make sure or to add it, do this:

* Right click on your project name in the solution explorer.
* Click "properties"
* Click on the "server" tab on the left.
* Click the link labelled "Configuration file". You will probably need admin privileges to edit the php.ini file.
* Scroll all the way to the bottom where it says "[ExtensionList]"
* In that section add a line that says "extension=php_pdo_mysql.dll"
* Save the file, close notepad and restart your debug session in VS.

For how to use PDO, look at the PDO documentation on php.net: http://php.net/manual/en/book.pdo.php

Re: Problem with mysql connections

PostPosted: February 13th, 2017, 8:06 pm
by Jaood
Thanks, your advice with mysqli works fine, so this topic can be closed.