日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

php和mysql函数的区别吗,(PHP,MySQL)函数仅在2种情况中的1种有效,找不到区别

發布時間:2025/3/15 数据库 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php和mysql函数的区别吗,(PHP,MySQL)函数仅在2种情况中的1种有效,找不到区别 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

因此,我具有此功能來搜索MySQL數據庫中的條目:

private function SearchContributors($search)

{

$search_pieces = explode(' ', $search);

if (count($search_pieces) == 1 )

{

$this->db->like('firstname', $search);

$this->db->or_like('lastname', $search);

$result = $this->db->get(); //the line from the error message below

}

//Other stuff for 2 and more pieces

return $result;

}

?>

我有兩次使用該功能.

案例A是用戶發起的搜索,并從URL(domain.com/contributors/?x=paul)獲取搜索查詢.這很好.

if (isset($_GET['x']))

{

$x = $_GET['x'];

$result = $this->SearchContributors($x);

}

?>

情況B是用戶輸入無效的子彈名稱(domain.com/contributors/paul代替domain.com/contributors/pauline-surname)并直接獲取搜索查詢時的備份:

$this->db->where('slug', $slug);

$result = $this->db->get();

if ($result->num_rows() == 0)

{

$x = str_replace('-', ' ', $slug);

$result = $this->SearchContributors($x);

}

?>

這返回了MySQL語法錯誤:

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘WHERE firstname LIKE ‘%paul%’ OR lastname LIKE ‘%paul%” at line 2

SELECT * WHERE firstname LIKE ‘%paul%’ OR lastname LIKE ‘%paul%’

Filename: /www/htdocs/w00a94ee/c/controllers/contributors.php

Line Number: 23

在這兩種情況下,該函數都具有完全相同的字符串保羅,那么為什么它不起作用?

//編輯

function __construct()

{

parent::__construct();

$this->load->database('databasename');

$this->db->from('tablename');

}

解決方法:

您忘記了指定要從中選擇哪個表.

$this->db->from('tablename');

編輯:問題是您在構造函數中添加from,然后您調用:

$this->db->where('slug', $slug);

$result = $this->db->get();

在致電SearchContributors之前.這將運行查詢并重置變量.

因此,當您調用SearchContributors時,將不再設置FROM.

您需要將$this-> db-> from(‘tablename’);在SearchContributors而不是構造函數中.使模型函數自成一體,而不需要外部函數(例如__construct來調用它們)通常是一個好主意.

標簽:codeigniter,mysql,php

來源: https://codeday.me/bug/20191127/2077035.html

總結

以上是生活随笔為你收集整理的php和mysql函数的区别吗,(PHP,MySQL)函数仅在2种情况中的1种有效,找不到区别的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。