CodeIgniter Database Connection Query

Source: Internet
Author: User

Just contact CI, to manipulate the database has not found the right way.

Environment: Wampserver CI

Problem: Query the data from the table in the phpMyAdmin, error:

1,Message:object of class Ci_db_mysqli_result could not being converted to string"

2.Message:array to string conversion

3,message:syntax error, unexpected ' name ' (t_constant_encapsed_string), expect t_constant_ Encapsed_string

Reason:

There are many types of data stored in the database, you want to take the type of data, the environment does not necessarily support, so PHP and MySQL communication between the full use of string.

and $query= $this->db->query ($sql); The data returned is type object. To remove the results from the $query and query by field. The specific code is shown below.

<?php
class Dbtest extends ci_controller{public
	function Index () {
		echo ' What a good day! ';
	}
	Public Function Dbcon () {
		$this->load->database ();
		$sql = "SELECT * from Clientcount where ID =3";
		$query = $this->db->query ($sql);
 
		if (! $this->db->simple_query ($sql))
		{
   			 $error = $this->db->error (); 
		} 
		if ($query->num_rows () >0) {
			$result = $query->result (); 
			foreach ($result as $row)
			{
				echo $row->id;
				echo $row->name;
			}
				
		}
		Else{
			echo False}
		}
? >


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.