Trac3 !! Posted October 20, 2009 Report Share Posted October 20, 2009 (edited) Sveiki. mēģinu panākt šādu lietu: $mysqli = array( "localhost", "username", "password", "database" ); $sql = new mysqli(implode(",",$mysqli)); kļūdas paziņojums: Warning: mysqli::mysqli(): php_network_getaddresses: getaddrinfo failed: No such host is known. in xxxxxxxx on line 42 Warning: mysqli::mysqli(): [2002] php_network_getaddresses: getaddrinfo failed: No such host is kn (trying to connect via tcp://localhost,username,password,database:3306) in xxxxxxxx on line 42 Warning: mysqli::mysqli(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known. in xxxxxxxx Ideja ir ka padod masīvu un tad to izmanto, lai padotu parametrus kadai klasei, šajā gadijumā mysqli. Edited October 20, 2009 by Trac3 !! Quote Link to comment Share on other sites More sharing options...
briedis Posted October 20, 2009 Report Share Posted October 20, 2009 Nu loģiski ka nevar. Implode uztaisa vienu stringu. $str = implode(",",$mysqli) //$str = "viens,otrs,divi,triis"; Tev tur prasa 4 parametrus, a tu padod viņam vienu stringu. Dari tā new mysqli($mysqli[0],$mysqli[1],$mysqli[2],$mysqli[3]); Quote Link to comment Share on other sites More sharing options...
Trac3 !! Posted October 20, 2009 Author Report Share Posted October 20, 2009 aa nu pareiz :D bet jebkurā gadijuma new mysqli($mysqli[0],$mysqli[1],$mysqli[2],$mysqli[3]); variants neder, jo katrai klasei ir savs mainīgo skaits.. kā citādi to varētu padot? :) Quote Link to comment Share on other sites More sharing options...
briedis Posted October 20, 2009 Report Share Posted October 20, 2009 (edited) Godīgi sakot, nezinu vai tā varēs. Kā tu vari padot kkādu noteiktu kopu ar parametriem, ja nemaz nezini cik viņi tiek prasīti, vai vispār kādā secībā? Ja tu zini, ka vienmēr būs tādā secībā, tad gribētu pajautāt, cik dažādām un kādām funkcijām taisies padot viņus? :D Man liekas, tas ko vēlies panākt ir galīgi sķērss programmēšanas stils... Edited October 20, 2009 by briedis Quote Link to comment Share on other sites More sharing options...
Kavacky Posted October 20, 2009 Report Share Posted October 20, 2009 Tas neizskatās pēc šķērsa stila, tas izskatās pēc idiotijas. Bet nu ja ļoti gribas, lai visur padotu tikai vienu masīvu, tad var no sērijas "my_mysqli Extends mysqli" visām klasēm, un tad konstruktoru savu uztaisīt, kurš padod, kādā secībā vajag, pārējais inherited. Bet tas ir vairāk nekā sviests. Quote Link to comment Share on other sites More sharing options...
indoom Posted October 21, 2009 Report Share Posted October 21, 2009 Iespējams šitādi eval("\$sql = new mysqli('" . implode("','",$mysqli) . "')"); Quote Link to comment Share on other sites More sharing options...
bubu Posted October 21, 2009 Report Share Posted October 21, 2009 eval nav smuki. Tā vietā labāk izmanto call_user_func_array funkciju: $object_class = "mysqli"; $constructor_arguments = array("111", "222", "333", ...); $obj = new $object_class(); call_user_func_array(array($obj, '__construct'), $constructor_arguments); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.