دالة mysql_connect() في PHP mysql

تعريف والاستخدام

يفتح دالة mysql_connect() اتصال MySQL غير المستدام.

النحو

mysql_connect(server,user,pwd,newlink,clientflag)
معلمات وصف
server

اختياري. تحديد الخادم الذي يتم الاتصال به.

يمكن تضمين رقم المنفذ، مثل "hostname:port"، أو مسار إلى套ة الاتصال المحلية، مثل لـ localhost ":/path/to/socket".

إذا لم يتم تعريف التعليمات البرمجية mysql.default_host في PHP (الحالة الافتراضية)، فإن القيمة الافتراضية هي 'localhost:3306'.

user اختياري. اسم المستخدم. القيمة الافتراضية هي اسم مالك عملية الخادم.
pwd اختياري. كلمة المرور. القيمة الافتراضية هي كلمة المرور الفارغة.
newlink اختياري. إذا تم استدعاء mysql_connect() مرة أخرى باستخدام نفس المعلمات، لن يتم إنشاء اتصال جديد، بل سيتم العودة إلى معرف الاتصال المفتوح بالفعل. يمكن تغيير هذا السلوك باستخدام المعلمات new_link بحيث يفتح mysql_connect() دائمًا اتصالًا جديدًا، حتى لو تم استدعاء mysql_connect() مرة أخرى باستخدام نفس المعلمات.
clientflag

Optional.clientflags The parameters can be a combination of the following constants:

  • MYSQL_CLIENT_SSL - Uses SSL encryption
  • MYSQL_CLIENT_COMPRESS - Uses compression protocol
  • MYSQL_CLIENT_IGNORE_SPACE - Allows spaces after the function name
  • MYSQL_CLIENT_INTERACTIVE - Allows non-active timeout before closing the connection

Return Value

If successful, it returns a MySQL connection identifier, or FALSE if it fails.

Tips and Comments

Note:When the script ends, the connection to the server is closed unless it has been explicitly called earlier. mysql_close() Closed.

Tip:To create a persistent connection, use mysql_pconnect() Functions.

Example

<?php
$con = mysql_connect("localhost","mysql_user","mysql_pwd");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
// Some code...
mysql_close($con);
?>