Skip to content

ErcanOPAK.com

  • ASP.Net WebForms
  • ASP.Net MVC
  • C#
  • SQL
  • MySQL
  • PHP
  • Devexpress
  • Reportviewer
  • About
MySQL / PHP

mysql_connect() in PHP 7

- 14.09.19 | 22.11.19 - ErcanOPAK

After upgrading  to  PHP 7.x from PHP 5.x, you start getting  error of “Call to undefined”.

This is because mysql_* functions are completely removed from PHP 7, it was get deprecated in PHP 5.5 but now it is completely removed.

The older mysql function are removed due to following reasons:

  1. Not work on Object Oriented concept
  2. Not support transactions and prepared statements
  3. Insecure

Here is how you can connect to MySQL with MySqli connection object:

<?php

$conn = mysqli_connect("localhost", "username", "password", "database");

?>

or more detailed:

<?php

try 
{
    $conn = mysqli_connect("localhost", "username", "password") or die("Error: " . $mysqli_connect_error());
    $db = mysqli_select_db($conn, "database");
} 
catch (Exception $e) 
{
    die("Unexpected Error: " . $e->getMessage());
}

?>

So, before you upgrade to PHP 7.x, first you must update your code.

Related posts:

Navigate to a Div using a button in HTML
Repeater Function in PHP
Disable REST API Plugin
How to connect MySQL Database with PHP
Post Views: 88

Post navigation

How to trim whitespaces between characters in C#
How to solve “PHP Update Required” warning on WordPress

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

May 2023
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
293031  
« Mar    

Most Viewed Posts

  • Get the First and Last Word from a String or Sentence in SQL (586)
  • Get the User Name and Domain Name from an Email Address in SQL (469)
  • Add Constraint to SQL Table to ensure email contains @ (358)
  • How to select distinct rows in a datatable in C# (302)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (296)
  • Average of all values in a column that are not zero in SQL (277)
  • Confirm before process with ASPxButton in Devexpress (273)
  • Find numbers with more than two decimal places in SQL (270)
  • ASPxGridView – Disable CheckBox based on condition in GridViewCommandColumn (256)
  • How to solve “Response.Redirect cannot be called in a Page callback” for DevExpress Components (236)

Recent Posts

  • Solution for “utf8mb4 requires a newer client library” error in WordPress
  • How to use TrimEnd to remove last character from string in C#
  • What is the difference between “int” and “uint” / “long” and “ulong”?
  • How to solve the stucking on “Loading Packages” phase for SSMS installation
  • Geçmiş Olsun Türkiyem
  • What is the difference between ‘ref’ and ‘out’ keywords in C#
  • How to check if javascript is enabled on the client’s browser
  • How to disable ASP.Net button after click to prevent double clicking
  • What is the difference between HashSet and List in .net?
  • What is the purpose of nameof in C#?

Most Viewed Posts

  • Get the First and Last Word from a String or Sentence in SQL (586)
  • Get the User Name and Domain Name from an Email Address in SQL (469)
  • Add Constraint to SQL Table to ensure email contains @ (358)
  • How to select distinct rows in a datatable in C# (302)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (296)

Recent Posts

  • Solution for “utf8mb4 requires a newer client library” error in WordPress
  • How to use TrimEnd to remove last character from string in C#
  • What is the difference between “int” and “uint” / “long” and “ulong”?
  • How to solve the stucking on “Loading Packages” phase for SSMS installation
  • Geçmiş Olsun Türkiyem

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter

© 2023 ErcanOPAK.com

Proudly powered by WordPress | Theme: Xblog Plus by wpthemespace.com