1

i am very new to stackoverflow so please let me know if i need to provide more information.

My issue started earlier today when i tried i enter this code ALTER TABLE tbl_name CONVERT TO CHARACTER SET charset_name; in the SQL QUERY.

After that all pages which is connected to my dbc.php get this error in return: Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /customers/1/b/3/fomo.no/httpd.www/dbc.php:9 Stack trace: #0 {main} thrown in /customers/1/b/3/fomo.no/httpd.www/dbc.php on line 9

My dbc code where the error msg is telling me the error is(line 9) i use the MSQL connection code:

line9    $link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");
 line10   $db = mysql_select_db(DB_NAME, $link) or die("Couldn't select database");

I use PHPmyadmin through one.com. I have been searching for a while and i cant find the solution anyware.

As said, i am very new please tell me if i need to provide more information. Thank you for your time and your help.

Your Common Sense
  • 154,967
  • 38
  • 205
  • 325
Tom James
  • 69
  • 10
  • Possible duplicate of [Call to undefined function mysql\_connect](http://stackoverflow.com/questions/8551398/call-to-undefined-function-mysql-connect) – Gouda Elalfy Dec 09 '15 at 22:11
  • I did see that one aswell, but it did not help me out. I will try to read it once more – Tom James Dec 09 '15 at 22:12
  • 4
    Sounds like your hosting site doesn't load the obsolete `mysql` extension. You should use `mysqli` or `PDO` instead. – Barmar Dec 09 '15 at 22:13
  • Yes @Barmar. Don't waste your time troubleshooting this. – AbraCadaver Dec 09 '15 at 22:13
  • 1
    That query is unrelated to the error you are describing. Maybe your hosting company updated to PHP 7 today and coincidentally you ran that query.. In any event update to `mysqli` or `pdo`. – chris85 Dec 09 '15 at 22:20
  • @chris85 yes they updated to php 7 today! I did not think of that! What should i do? What is pdo? – Tom James Dec 09 '15 at 22:29
  • [PDO](http://php.net/manual/en/book.pdo.php) is the newer, database-agnostic driver architecture for accessing MySQL, PostgreSQL, Oracle, MSSS &c. &c. using a common set of calls. – Darwin von Corax Dec 09 '15 at 22:45

2 Answers2

0

As the comments say, the mysql driver is no longer available in PHP 7. To replace your sample code with PDO, you would use

$dsn = 'mysql:host=$dbhost;dbname=$dbname';
$dbh = new PDO($dsn, $dbuser, $dbpasswd);

and then

$stmt = $dbh->prepare($query_string);
$result = $stmt->execute($bind_params);

I leave error handling, as well as reading up on prepared statements and bind parameters, as an exercise for the reader.

Darwin von Corax
  • 5,138
  • 3
  • 17
  • 27
-1

mysql_connect() NOT SUPPORT TO php7 SO REPLACE WITH mysqli_connect()

Roman Marusyk
  • 21,493
  • 24
  • 66
  • 105