PHP mysql_connect with MySQL and executes SQL statements

Source: Internet
Author: User

Novice initial examination, but also please the road Master a lot of guidance.

The program source code is as follows:

<?php
$conn = mysql_connect ("localhost", "root", "") or Die ("wrong!");
$sel =mysql_select_db ("MyDB", $conn);
$sql = "INSERT into ' mydb '. ' Test ' (
' ID ',
' UID ',
' RegDate ',
' Remark '
)
VALUES (
', ' php200 ', now (), ' dddd '
) ";
$que =mysql_query ($sql, $conn);
if ($que)
echo "true";
Else
echo "wrong";
?>

The mysql_connect () function opens a non-persistent MySQL connection.

Grammar

Mysql_connect (Server,user,pwd,newlink,clientflag)

parameters Description
server

Optional. Specify the server to connect to.

Can include a port number, such as "Hostname:port", or a path to a local socket, such as ":/path/to/socket" for localhost.

If the PHP directive mysql.default_host not defined (by default), the default value is ' localhost:3306 '.

user is optional. User name. The default value is the user name of the server process owner.
pwd is optional. Password. The default value is a blank password.
newlink is optional. If mysql_connect () is invoked the second time with the same argument, no new connection will be established, and the connection ID that is already open will be returned. The parameter New_link changes this behavior and causes mysql_connect () to always open a new connection, even when mysql_connect () was previously invoked with the same parameters.
clientflag

Optional. The Client_flags parameter can be a combination of the following constants:

    Mysql_client_ssl-using SSL encryption
  • Mysql_c Lient_compress-Use the compression protocol
  • Mysql_client_ignore_space-Allow the interval after the function name
  • mysql_client_interactive-Allow off Interaction timeout before a closed connection time inactive

return value

If successful, returns a MySQL connection identity and returns FALSE if it fails.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.