Whats wrong with this PHP code?

by Mrnace
10 replies
mysql_connect ("localhost", "nathan_userblog", "");

I've removed the password, but I get an error saying its depricated.

It reads below -

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home1/nathan/public_html/Blog.php on line 2

How to I correct this?
#code #php #wrong
  • Profile picture of the author yukon
    Banned
    Try mysqli_connect
    {{ DiscussionBoard.errors[10742574].message }}
  • Profile picture of the author Mrnace
    would I have to insert the i ever time I mention mysql?
    {{ DiscussionBoard.errors[10742577].message }}
  • Profile picture of the author Mrnace
    Its made no different, still shows an error.

    Any other ideas?
    {{ DiscussionBoard.errors[10742582].message }}
  • Profile picture of the author Mrnace
    Getting these errors now -

    Warning: mysqli_query() expects at least 2 parameters, 1 given in /home1/nathan/public_html/Blog.php on line 50

    Line 50 -

    $sql = mysqli_query("SELECT * FROM blog1data ORDER BY id DESC");

    Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home1/nathan/public_html/Blog.php on line 51

    Line 51 -

    while ($row = mysqli_fetch_array ($mysqli_result, $sql)){
    {{ DiscussionBoard.errors[10742600].message }}
  • Profile picture of the author SteveJohnson
    See this page to learn how to use PHP mysqli library: PHP mysqli_fetch_array() Function

    Your questions are answered there, just have a look at the code and compare it to what you're doing.
    Signature

    The 2nd Amendment, 1789 - The Original Homeland Security.

    Gun control means never having to say, "I missed you."

    {{ DiscussionBoard.errors[10743434].message }}
    • Profile picture of the author Mrnace
      Originally Posted by SteveJohnson View Post

      See this page to learn how to use PHP mysqli library: PHP mysqli_fetch_array() Function

      Your questions are answered there, just have a look at the code and compare it to what you're doing.
      I done my best with this and getting alot of syntax errors which I think are a little pedantic.

      Im totally confused.
      {{ DiscussionBoard.errors[10747942].message }}
  • Profile picture of the author Sun Tzi
    [DELETED]
    {{ DiscussionBoard.errors[10745000].message }}
    • Profile picture of the author Sun Tzi
      To show no errors or warnings type
      PHP Code:
      error_reporting(0); 
      For the message;
      Code:
      Warning: mysqli_query() expects at least 2 parameters, 1 given in /home1/nathan/public_html/Blog.php on line 50
      YOU MUST SUBTITUDE THE §-Sign WITH THE $-Sign, BECAUSE OF THE FORUMS SOFTWARE WHITCH REMOVES THE WHOLE VARIABLE IF IT BEGINS WITH $


      Fix for line 50:
      PHP Code:
      §result mysqli_query(§connection§query); //§connection = result of mysqli_connect (must be from type ressource) 
      Fix for line 51
      PHP Code:
      while( Â§row mysqli_fetch(§result)) {
        
      //e.g. print_r(§row);

      Cleanest version
      PHP Code:
      while((§row =mysqli_fetch(§result)) !== null) {
        
      //e.g. print_r(§row);

      {{ DiscussionBoard.errors[10745010].message }}
      • Profile picture of the author Mrnace
        Originally Posted by Sun Tzi View Post

        To show no errors or warnings type
        PHP Code:
        error_reporting(0); 
        For the message;
        Code:
        Warning: mysqli_query() expects at least 2 parameters, 1 given in /home1/nathan/public_html/Blog.php on line 50
        YOU MUST SUBTITUDE THE §-Sign WITH THE $-Sign, BECAUSE OF THE FORUMS SOFTWARE WHITCH REMOVES THE WHOLE VARIABLE IF IT BEGINS WITH $


        Fix for line 50:
        PHP Code:
        §result mysqli_query(§connection§query); //§connection = result of mysqli_connect (must be from type ressource) 
        Fix for line 51
        PHP Code:
        while( Â§row mysqli_fetch(§result)) {
          
        //e.g. print_r(§row);

        Cleanest version
        PHP Code:
        while((§row =mysqli_fetch(§result)) !== null) {
          
        //e.g. print_r(§row);

        How do I get that symbol?
        {{ DiscussionBoard.errors[10747943].message }}
        • Profile picture of the author robomedia
          Just turn off error reporting, "deprecated" isn't an error itself.
          Did that code ever worked if so when did it stop? Maybe your problem is somewhere else .
          {{ DiscussionBoard.errors[10747977].message }}
  • Profile picture of the author zardon
    Change the PHP ini file to only report errors and ignore warnings.
    If you want you can put @ in front of php commands like mysql connect to prevent it outputting those kind of warnings.
    {{ DiscussionBoard.errors[10773430].message }}
  • Profile picture of the author element121
    [DELETED]
    {{ DiscussionBoard.errors[10774197].message }}

Trending Topics