My Sql Functions With Examples
Program
to get the details of all the columns of “emp” table?
<?php
echo
"<h1>";
$con = mysql_connect('localhost','root','');
mysql_select_db("emp");
$res =
mysql_query("select * from emp1");
$i =0;
while($i< mysql_num_fields($res))
{
echo "<u> information for
columns".($i+1).":</u><br>";
$meta = mysql_fetch_field($res,$i);
echo "<pre>
Blob :
$meta->blob
Max_length :
$meta->max_length
Name :
$meta->name
Not-Null :
$meta->not_null
Numeric :
$meta->numeric
Primary-key :
$meta->primary_key
Table :
$meta->table
Type :
$meta->type
Default :
$meta->def
Unique-key :
$meta->unique_key
Unsigned :
$meta->unsigned
Zerofill :
$meta->zerofill
</pre>";
$i++;
}
mysql_close();
?>
OutPut:
information for
columns1:
Blob :
0
Max_length :
3
Name :
empno
Not-Null :
1
Numeric : 1
Primary-key :
1
Table :
emp1
Type :
int
Default :
Unique-key :
0
Unsigned :
0
Zerofill :
0
information for columns2:
Blob :
0
Max_length :
12
Name :
ename
Not-Null :
0
Numeric :
0
Primary-key :
0
Table :
emp1
Type :
string
Default :
Unique-key :
0
Unsigned :
0
Zerofill :
0
information for
columns3:
Blob :
0
Max_length :
7
Name :
sal
Not-Null :
0
Numeric :
1
Primary-key :
0
Table :
emp1
Type :
real
Default :
Unique-key :
0
Unsigned :
0
Zerofill :
0
7.mysql_fetch_lengths(mywql
result): get the length of each ouput in a result.
<?php
echo
"<h1>";
$con =
mysql_connect('localhost','root','');
mysql_select_db('emp');
$res =
mysql_query("select * from emp1 where empno=101");
$record =
mysql_fetch_assoc($res);
print_r($record);
echo
"<br><br>";
$length =
mysql_fetch_lengths($res);
print_r($length);
?>
OutPut:
Array ( [empno] =>
101 [ename] => penna [sal] => 123.45 )
Array ( [0] => 3 [1]
=> 5 [2] => 6 )
8.mysql_field_len(mysql
result , int $field_offset) : returns the length of
the specified field.
9.mysql_field_name(mysql
result , int $field_offset) : get the name of the
specified field in a result.
10.mysql_field_type(mysql
result,int $field_offset) : get the type of the
specified field in a result.
<?php
echo
"<h1>";
$con =
mysql_connect('localhost','root','');
mysql_select_db('emp');
$rs =
mysql_query("select * from emp1");
$i=0;
while($i< mysql_num_fields($rs))
{
echo mysql_field_name($rs,
$i)."--".mysql_field_table($rs,
$i)."--".mysql_field_len($rs, $i)."<br>";
$i++;
}
?>
OutPut:
empno--emp1--10
ename--emp1--20
sal--emp1—10
1.
Mysql_free_result(mysql
result) : free mysql
result memory.
2.
Mysql_get_client_info()
3.
Mysql_get_host_info()
4.
Mysql_get_proto_info()
5.
Mysql_get_server_info()
6.
Mysql_info()
7.
Mysql_num_fields(mysql
result): get number of
fields in result resource.
8.
Mysql_num_rows(mysql
result): get number of rows/records in result resource.
9.
Mysql_ping($conn)
:
ping a server connection or reconnect if there is no connection.
Being new to the blogging world I feel like there is still so much to learn. Your tips helped to clarify a few things for me as well as giving..
ReplyDeleteStudy Abroad Consultants in Chennai | Study in Germany Consultants in Chennai | Germany Education Consultants in Chennai
These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.
ReplyDeleteSharepoint Training in Chennai
It’s really amazing that we can record what our visitors do on our site. Thanks for sharing this awesome guide. I’m happy that I came across with your site this article is on point,thanks again and have a great day. Keep update more information..
ReplyDeleteOffice Interiors in Chennai
Interior Decorators in Chennai
Your posts is really helpful for me.Thanks for your wonderful post.It is really very helpful for us and I have gathered some important information from this blog. so keep sharing..
ReplyDeleteJournal Of Computer Science
Journal Of Management
Plagiarism service
Engineering Journal
Journal Of Chemistry
ReplyDeleteThanks For Sharing. It IS very helpful For Everyone ....
If You Are Looking Best PHP training in chandigarh click here