-2

Problem in my php code

function connect()
{
    $connector = mysql_connect("localhost","root","");
    mysql_set_charset('utf8',$connector);
    if($connector)
    {
        if(mysql_select_db("news",$connector))
            return true;
            return false;
    }
    return false;
}

if(connect())
{
    $query="SELECT * FROM category";
    $result=mysql_query($query);
    if($result)
    {
        while($row=mysql_fetch_array($result,MYSQL_ASSOC) )
        {
        ?> <li><a href=""><?php echo $row['catName']; ?></a></li>
        <?php
        }
    }   
}

my php version is 5.5.12 & use wamp server 2.5 My code tells me this:

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO & in php

What does that mean and how can I handle it?

Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
  • 4
    The error is self-explanotary : the mysql driver is now deprecated, use mysqli or pdo to connect to your database. Like mysqli_connect for exemple :) (note the "i") – Adrian Tombu Dec 30 '15 at 07:55
  • i use : $connector = mysqli_connect("localhost","root","","news"); $sql="SELECT * FROM akhbar ORDER BY id DESC LIMIT 1"; $result = $connector->query($sql); while($row = $result->fetch_assoc()) { echo "id: " . $row["id"]. " - Name: " . $row["title"]. " " . $row["matn"]. "
    "; } it dont worked !!
    – Hossein Bustanchi Dec 30 '15 at 08:05

1 Answers1

2

The error is pointing the matter well

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO & in php

Why shouldn't I use mysql_* functions in PHP?(link)

Error in php.net

This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.

Use

  1. MySQLi
  2. PDO_MySQL

As well as per your comment

You are conflicting MySQL and MySQLi. MySQL and MySQLi are two different Methods

Community
  • 1
  • 1
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85