-3

Keep getting this line now when i run my sql query:

Deprecated: mysql_pconnect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\Users\Murray\Desktop\YouthCafeWork\BookingSystem\bookingrequest.php on line 43

I have tried to change it so that it is using the new syntax but i can not get it to work.

Line 43 (the error line is) is :

$db = mysql_pconnect('localhost', 'root', '');

Thanks for any help in advance :)

Ende Neu
  • 15,581
  • 5
  • 57
  • 68
FallingStar
  • 1
  • 1
  • 5
  • 2
    Did you have looked at the [red box](http://de1.php.net/manual/en/function.mysql-pconnect.php)? – VMai Aug 05 '14 at 09:02
  • 1
    Did you read the error message? "*use mysqli or PDO instead*" – h2ooooooo Aug 05 '14 at 09:03
  • 1
    I suggest adding the code you *tried* instead that you couldn't get working. Note you need to replace all the code that works with your DB, not just the `connect` statement. – Marty Aug 05 '14 at 09:04
  • yes i did read the red box and yes i did read the error message. I am just unsure of how to use mysqli? – FallingStar Aug 05 '14 at 09:04
  • `mysqli_connect() with p: host prefix` is pretty straight forward. – fpietka Aug 05 '14 at 09:05
  • 1
    The entire `mysql` extension is deprecated, not just that one function. You need to recode everything using `mysqli` or `PDO`. – Barmar Aug 05 '14 at 09:08

4 Answers4

1

As the documentation of mysql_pconnect() is stating, you should use mysqli_connect() with p: host prefix:

$db = mysqli_connect('p:localhost', 'root', '');
fpietka
  • 1,027
  • 1
  • 10
  • 23
  • 1
    Better yet: drop the _persistent_ bit all together... a stateless language, like PHP, and a persistent connection doesn't make much sense. [there are disadvantages](http://stackoverflow.com/questions/3332074/what-are-the-disadvantages-of-using-persistent-connection-in-pdo) to consider – Elias Van Ootegem Aug 05 '14 at 09:12
1

I suggest you use either mysqli or PDO for your database connections.

you should read on PDO and mysqli

PDO connections are done this way

$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);

mysqli connection is done this way

$con = mysqli_connect("localhost","my_user","my_password","my_db");
Kxng Kombian
  • 467
  • 4
  • 13
0

support from php for mysql has been deprecated and will be removed very soon so the warning is displayed. use this- object oriented style -

$mysqli = new mysqli("localhost", "my_user", "my_password", "test"); $mysqli->select_db("world");

or Procedural style

$link = mysqli_connect("localhost", "my_user", "my_password", "test");mysqli_select_db($link, "world");

Sougata Bose
  • 31,517
  • 8
  • 49
  • 87
-3

As you can see here: http://php.net/manual/en/function.mysql-pconnect.php

mysql_pconnect function is deprecated. Insted of use this function, use: mysqli_connect

For more info, see: http://www.w3schools.com/php/php_ref_mysqli.asp

and:

http://code.tutsplus.com/tutorials/php-database-access-are-you-doing-it-correctly--net-25338

EDIT:

Try this (if you did not set a root password for your mysql server):

$db = new mysqli('localhost', 'root', NULL, 'dabase_name');

Regards PS

WeezHard
  • 1,982
  • 1
  • 16
  • 37
  • Answers with links to solutions aren't a good format for SO. Try answering the question directly using links as a supporting. (dv wasn't me) – David Barker Aug 05 '14 at 09:08
  • 1
    Please try to provide links to the official PHP documentation, and *especially* not W3Schools. – Marty Aug 05 '14 at 09:08
  • Dear @DavidBarker I Answers commenting. I use the link only for her references. What is wrong with that? Is the same to post a Book Title Reference – WeezHard Aug 05 '14 at 09:10
  • yeah i have tried to do this at the moment i am using `$db = mysql_pconnect('localhost', 'root', '');` and i have tried to change this to the mysqli way `$db = mysqli_connect("localhost","root");` is this correct, i think it needs the root password and db name but i do not know what the password is as i have not needed it before? – FallingStar Aug 05 '14 at 09:11
  • [SO: How do I write a good answer?](http://stackoverflow.com/help/how-to-answer) `[...]Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline.[...]` – t.niese Aug 05 '14 at 09:15
  • @FallingStar what error did you receaved ? You MySQL server have a root password setted up ? If not, try this: $db = new mysqli('localhost', 'root', NULL, 'database_name'); – WeezHard Aug 05 '14 at 09:15