2015-06-04 9 views
6

कृपया मुझे बताएं कि मैंने क्या गलत किया है? और बेस के साथ बेहतर तरीके से कैसे काम करें? कनेक्शन काम करता है, लेकिन मैं आधार से जानकारी नहीं देख सकता। मैं तो बस मिलती है:PHP ओओपी और MySQLi कनेक्शन = घातक त्रुटि: अपरिभाषित विधि पर कॉल करें mysqli :: arrayQuery()

Fatal error: Call to undefined method mysqli::arrayQuery()

मैं नहीं समझ सकता है कि यह कैसे तय करने के लिए, गूगल या तो मदद नहीं की।

<?php 
class Proc{ 
    protected $DB; 
    function __construct(){ 
     $this->DB=new mysqli('localhost', 'user', 'password', 'basename'); 
     $this->DB->query("set names utf8");} 
    function __destruct(){unset($this->DB);} 
    function GetAll(){ 
     $sql="SELECT * FROM users"; 
     $result = $this->DB->arrayQuery($sql, SQLITE_ASSOC); 
     return $result;} 
} 

$Yo = new Proc(); 

$users = $Yo->GetAll(); 
echo "All users: ".count($users); 
foreach ($users as $user){ 
    $id = $user["ID"]; 
    $n = $user["Name"]; 
    echo "{$id} - {$n}<br/>";} 
?> 

थोड़ा फिक्स और सभी सही काम करते हैं! सभी को धन्यवाद!

<?php 
class Proc{ 
    protected $DB; 
    function __construct(){ 
     $this->DB=new PDO("mysql:host=localhost;dbname=basename", user, password); 
     $this->DB->query("set names utf8");} 
    function __destruct(){unset($this->DB);} 
    function GetAll(){ 
     $sql="SELECT * FROM users"; 
     $result = $this->DB->query($sql); 
     return $result;} 
} 
$Yo = new Proc(); 
$users = $Yo->GetAll(); 
foreach ($users as $user){ 
    $id = $user["ID"]; 
    $n = $user["Name"]; 
    echo "{$id} - {$n}<br/>";} 
?> 
+0

अपरिभाषित विधि mysqli करने के लिए कॉल :: arrayQuery() - मेरा मतलब है त्रुटि संदेश CEAR है, है न? – panther

+0

क्या आप इस फ़ंक्शन को 'arrayQuery' पोस्ट कर सकते हैं यदि आपके पास –

+0

है http://php.net/manual/en/book.mysqli.php की जांच से पता चलता है कि' arrayQuery' उपलब्ध नहीं है (mysqli क्लास में ऐसी विधि नहीं है)। साथ ही, पीडीओ –

उत्तर

1

आप किस डेटाबेस का उपयोग कर रहे हैं? SQLite या mysql?

क्योंकि PHP DOCS के अनुसार, मैं समारोह लगता arrayQuery केवल SQLite डेटाबेस के लिए इस्तेमाल किया जा सकता

+0

MySQL 5.5.37, और "mysqli" के रूप में कनेक्ट करें। तो यह SQLite नहीं है? – Baaakaaa

+1

नहीं ... आपके पास MySQL डेटाबेस है, और चूंकि आपने "mysqli" शुरू किया है, इसलिए mysqli क्लास में वह विधि नहीं है – Abhinav

संबंधित मुद्दे