The background color when the element is selected.
Object-level plug- in
- Orange Fruit
- Celery Vegetable
- Banana Fruit
----Custom class-level plug-ins--twoaddresult
By invoking the different methods in the custom plug-in Twoaddresult, you can add and subtract two values, and after importing the plug-in, the calling format is:
$.addNum(p1,p2)
And $.subNum(p1,p2)
The call format is calculated as the result of adding and subtracting two values, p1 and P2 are arbitrary values.
custom class-level plug-ins
Subtract two numbers:
-
=
2, mysql&php
-----PHP built-in MySQL function (a)-----
----Connect to a database
Mysql_connect
mysql_connect (' localhost ', ' root ', ');
That is, this function has 3 parameters, database name or IP address , user name, password
Note that mysql_connect is generally considered to be no longer supported in later versions (php5.5 later versions seem to be) instead of mysqi_connect.
if (Mysqli_connect (' localhost ', ' root ', ')) {
echo "Connected successfully";
}else{
echo "Shit";
}
Test code above
After the connection is successful, the MySQL connection identifier is returned (the usefulness is mentioned below), and if it fails, it returns false.
--- database extensions
A database in PHP may have one or more extensions, both official and third-party. The usual extensions like MySQL have native MySQL libraries, you can also use the enhanced version of the mysqli extension, and you can use PDO for connection and operation.
Different extensions provide a basic approach to operations, but the difference is that there may be some new features, and operational performance may vary.
MySQL extension how to connect to a database:
$link = mysql_connect (' mysql_host ', ' mysql_user ', ' Mysql_password ');
MYSQLI Extensions:
$link = Mysqli_connect (' mysql_host ', ' mysql_user ', ' Mysql_password ');
PDO extension
$dsn = ' mysql:dbname=testdb;host=127.0.0.1 '; $user = ' dbuser '; $password = ' Dbpass '; $dbh = new PDO ($DSN, $user, $password);
----Close the database connection
Mysql_close
Mysql_close ($con); Closes the previous connection, where $con is the identifier returned after the mysql_connect () succeeds
$con =mysqli_connect (' localhost ', ' root ', ' ', ' info ');
----Select a database
mysql_select_db ()
$con =mysqli_connect (' localhost ', ' root ', ' ', ' info ');
if ($con) {
echo "Connected successfully";
}else{
echo "Shit";
}
Mysql_close ($con);
if (mysqli_select_db ($con, ' info ')) {
echo "Success";
}else{
echo "Shit";
}
Because my PHP version is high, MySQL basically do not recognize, so I have to use mysqli, but the basic usage is similar, is the parameter to pay attention to. Generally speaking, compiling software (I use Zend) is a hint, do not worry
----Execute SQL statements
Mysqli_query ()
Mysqli_query ($con, "INSERT test (name) VALUES (' Tom ')");
The mysqli is required to be connected, $con
---execute MySQL Query
After the database is established, queries can be made, and query instructions are sent to the database in the form of mysql_query plus SQL statements.
$res = mysql_query (' select * from user Limit 1 ');
The statement for the query class returns a resource handle (resource) from which the data in the query result set can be obtained.
$row = Mysql_fetch_array ($res); Var_dump ($row);
By default, PHP executes the query using the most recent database connection, but if there are multiple connections, you can query from that connection by parameter directives.
$link 1 = mysql_connect (' 127.0.0.1 ', ' code1 ', '); $link 2 = mysql_connect (' 127.0.0.1 ', ' code1 ', ', true); Open a new connection $res = mysql_query (' select * from user Limit 1 ', $link 1); Querying data from the first connection
Connecting to a database
mysql_connect (' 127.0.0.1 ', ' code1 ', ');
mysql_select_db (' Code1 ');
mysql_query ("Set names ' UTF8 '");
Do a data query here
$res = mysql_query ("SELECT * from User limit 1");
$row = Mysql_fetch_array ($res);
Var_dump ($row);
---inserting new data into MySQL
When we understand how to use mysql_query for data queries, then, similarly, inserting data is actually done by executing an SQL statement, for example:
$sql = "INSERT into user (name, age, Class) VALUES (' John Doe ', 18, ' 31 classes ')"; mysql_query ($sql); Execute INSERT statement
Usually data is stored in variables or arrays, so SQL statements need to be preceded by string concatenation.
$name = ' John doe '; $age = +; $class = ' high 31 classes '; $sql = "INSERT into user (name, age, Class) VALUES (' $name ', ' $age ', ' $class ')"; MySQL _query ($sql); Execute INSERT statement
In MySQL, after executing the INSERT statement, you can get the self-increment primary key ID, which can be obtained through PHP's mysql_insert_id function.
$uid = mysql_insert_id ();
This ID is very useful, and can often be used to determine whether the insert succeeds or to perform other data operations as an association ID.
Connecting to a database
mysql_connect (' 127.0.0.1 ', ' code1 ', ');
mysql_select_db (' Code1 ');
mysql_query ("Set names ' UTF8 '");
The known data variables have
$name = ' John Doe ';
$age = 18;
$class = ' High 31 classes ';
Do a data query here
$sql = "INSERT into user (Name,age,class) value (' $name ', ' $age ', ' $class ')";
mysql_query ($sql);
$uid =mysql_insert_id ();
Print_r ($UID);
To go back to the Chinese team and continue tomorrow.
http://www.bkjia.com/PHPjc/1072327.html www.bkjia.com true http://www.bkjia.com/PHPjc/1072327.html techarticle the morning will be the only way to do that?-jquery, morning-jquery Hi slept well why in the morning or not to see the paper, would rather do this, do not want to seriously read the paper. Feel the next ...