Questions tagged [mysql-connect]

The `mysql_connect` function opens a connection to a MySQL server.

The mysql_connect function opens a connection to a MySQL server. However, this function, along with all other mysql_* functions, are deprecated in PHP 5.5.0 and should be avoided (see the red box). Consider using prepared statements with either PDO or MySQLi instead.

192 questions
107
votes
14 answers

Undefined function mysql_connect()

I have ran aptitude install php5-mysql (and restarted MySQL/Apache 2), but I am still getting this error: Fatal error: Call to undefined function mysql_connect() in /home/validate.php on line 21 phpinfo() says the…
user1765369
  • 1,333
  • 3
  • 11
  • 19
26
votes
5 answers

mysql_connect VS mysql_pconnect

I have this doubt, I've searched the web and the answers seem to be diversified. Is it better to use mysql_pconnect over mysql_connect when connecting to a database via PHP? I read that pconnect scales much better, but on the other hand, being a…
rogeriopvl
  • 51,659
  • 8
  • 55
  • 58
25
votes
2 answers

MySQL credentials/hosts variables best practices

I want to know what is the best practice or what is recommended to do when a variables are created for MySQL credentials/host. define('HOST', 'localhost'); // etc.. mysql_connect(HOST, // etc... vs $host = 'localhost'; // etc.. …
Pat R Ellery
  • 1,696
  • 3
  • 22
  • 40
23
votes
2 answers

mysql_connect (localhost / 127.0.0.1) slow on Windows platform

I am using Windows 7, Apache 2, PHP 5, MySQL 5, all are on the same machine. I have found an interesting issue, I have the following code: $sql = "select * from user1"; $conn = mysql_connect("localhost", "root", "xxxxxxxx"); …
WaiKit Kung
  • 1,296
  • 1
  • 14
  • 15
16
votes
6 answers

mysql_connect(): No such file or directory

I have just installed a MySQL server (version 3.23.58) on an old RedHat7. I cannot install a more recent MySQL version because of the dependencies. I cannot update librairies on this RedHat server. However, I have a problem connecting to the…
Maxbester
  • 2,435
  • 7
  • 42
  • 70
11
votes
1 answer

Is mysql_connect() usable in PHP 5.6.5

Which is the latest version PHP version, who support mysql_connect()? I've want to upgrade my PHP version. I've read, that mysql_connect() are deprecated. In all Projects I've use the old mysql_connect(). Can I update to PHP 5.6.5 or is the command…
Reddi
  • 121
  • 1
  • 1
  • 4
11
votes
4 answers

Connecting to remote MySQL server using PHP

I am attempting to connect to a remote MySQL server from my local machine virtualhost using the following code: $conn = mysql_connect("$dbhost", "$dbuser", "$dbpass") or die(mysql_error()); mysql_select_db($dbname, $conn) or…
BenTheDesigner
  • 1,954
  • 3
  • 17
  • 21
10
votes
7 answers

Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /private/tmp/wordpress/wp-includes/wp-db.php on line 1452

I'm trying to run PHPUnit to unittest a WordPress plugin, but the error in the title keeps showing up. I used WP-CLI to setup the unittests, but also WP-CLI throws a similar error when I try to run it. I use MAMP to run the database. I have setup…
SomeNorwegianGuy
  • 1,494
  • 4
  • 17
  • 43
7
votes
2 answers

Wierd and Annoying error: Call to undefined function mysql_query()

I've been at this for more than an hour now, I can connect to my database and all (doesn't give any errors) but i get the following error when i try to use "mysql_query($query);" Call to undefined function mysql_query() I've already tried…
user2870011
  • 183
  • 1
  • 8
7
votes
5 answers

mysql_pconnect(): send of 5 bytes failed with errno=32 Broken pipe

I've been using the same DB abstraction library for years. But today it started writing these Notice (8) messages in my log. The application is working correctly but every time a script connects to the DB the same notice is logged. I cannot think…
user213154
6
votes
4 answers

Prevent Error on mysql_connect() - Access denied

I have this code snippet: $conn = mysql_connect($host, $usr, $pwd); How can I prevent PHP from printing an error message when MySQL access is denied? I need exactly this syntax but nothing works for me. I tried $conn = mysql_connect($host, $usr,…
headacheCoder
  • 4,503
  • 8
  • 30
  • 33
6
votes
5 answers

php pconnect vs connect

If I have a script which inserts data then exits, the script will be opened by 100 users at the same time or within 2 mins. (Actually I'm doing email tracking.) So pconnect is better, or connect is better to reduce the resource? I have close when…
user192344
  • 1,274
  • 6
  • 22
  • 36
5
votes
2 answers

Why do we have to close the MySQL database after a query command?

I'm starter. I want to know what will happen if we don't close the MySQL connection. 1- Is it possible to open more than one database if we don't close them? I mean can we open more than one database in a same time? 2- Does closing database increase…
UserMat
  • 600
  • 4
  • 10
  • 27
4
votes
4 answers

Windows 7 PHP MySQL Connection Issues

When I run $conn = mysql_connect($host, $user, $pass); I am able to get a connection to the database but when i do a var_dump($conn) I get back bool(true) which is limiting me from having multiple connection to multiple servers. The original setup…
Geoffrey Wagner
  • 818
  • 1
  • 5
  • 11
4
votes
3 answers

mysql_connect taking long time to execute

i have following script in php to login to mysql $db_host="localhost"; $db_user="root"; $db_pass="123"; $dbc=mysql_connect($db_host,$db_user,$db_pass) OR DIE (mysql_error()); $dbs=mysql_select_db($db_name) OR DIE (mysql_error()); …
air
  • 6,136
  • 26
  • 93
  • 125
1
2 3
12 13