0

I maked Database on SQL Server because i can use "instead of" for my triggers. I need to use wamp to do web application in php :

So i have installed dll of SQL Server, php.ini is edited to add "extension=php_sqlsrv_72_ts_x64.dll" and "extension=php_sqlsrv_pdo_72_ts_x64.dll". i do a phpinfo() to see if it was succefully installed, so i see pdo_sqlsrv and sqlsrv but it not appear in extension of php (when i click on the wamp logo > php > extension. my problem is that when i try to connect to my Database with :

$conn = sqlsrv_connect($serverName,$connectionInfo);

it say that sqlsrv_connect undefined function

In other case if it is not possible to fix this problem, i want to do the same Database on MySQL but there is not "instead of" for trigger, just "before" and "after", so is there a way to do this without "instead of" ?

the context of database is that there are equipment which are related to a type like "pc or screen or..." and if equipment is already related > rollback or if equipment is not created before relate it to a type > rollback

i hope that you can understand my problems and my bad english

thank you !

EDIT 1 : pictures of my database trigger on pc table (i apologize for french words) :

/* Trigger de contrainte pour le type de materiel pc ****************************************/
on pc
instead of
insert, update
as
/* Declaration des champs a inserer ou mettre a jour dans la table pc */
declare @pc_marque varchar(20)
declare @pc_modele varchar(30)
declare @pc_nomreseau varchar(30)
declare @pc_versionos varchar(20)
declare @pc_memoireram int
declare @pc_memoirestockage int
declare @pc_processeur varchar(20)
declare @pc_prof bit
declare @pc_mat int
declare @ecran_mat int
declare @imp_mat int
declare @vid_mat int
declare @idmat int
declare @pc_mat_verif int
declare @deleted int
declare BDPRO_CurseurPC cursor
for select pc_marque, pc_modele, pc_nomreseau, pc_versionos, pc_memoireram, pc_memoirestockage, pc_processeur, pc_prof, pc_mat from inserted
open BDPRO_CurseurPC
fetch next from BDPRO_CurseurPC into @pc_marque, @pc_modele, @pc_nomreseau, @pc_versionos, @pc_memoireram, @pc_memoirestockage, @pc_processeur, @pc_prof, @pc_mat
/*Pour chaque insertion ou mise à jour de PC*/
while @@FETCH_STATUS = 0
    begin
        set @deleted = (select COUNT(*) from deleted)
        set @ecran_mat = (select ecran_mat from ecran where ecran_mat = @pc_mat)
        set @imp_mat = (select imp_mat from imprimante where imp_mat = @pc_mat)
        set @vid_mat = (select vid_mat from videoprojecteur where vid_mat = @pc_mat)
        set @pc_mat_verif = (select pc_mat from Pc where Pc_mat = @pc_mat)
        set @idmat = (select mat_id from materiel where mat_id = @pc_mat)
        /* si le materiel auquel on veut associer le type est deja créer (Clé primaire existante)*/
        if (@idmat is not null)
             begin
            /* Si il n'y a rien dans la table deleted c'est donc une insertion*/
                if(@deleted <= 0)
                    begin
                    /* si le materiel n'est pas associé à l'un des types alors on insert*/
                        if ((@ecran_mat is null) and (@imp_mat is null) and (@vid_mat is null) and (@pc_mat_verif is null))
                            begin
                                insert into pc (pc_marque, pc_modele, pc_nomreseau, pc_versionos, pc_memoireram, pc_memoirestockage, pc_processeur, pc_prof, pc_mat)
                                values (@pc_marque, @pc_modele, @pc_nomreseau, @pc_versionos, @pc_memoireram, @pc_memoirestockage, @pc_processeur, @pc_prof, @pc_mat)
                            end
                        /* Si le materiel est deja associé alors on rollback*/
                        else
                            begin
                                print 'Il existe deja un type associé à ce materiel'
                                rollback transaction
                            end
                    end
                /* Si il y a quelque chose dans la table deleted c'est une mise à jour alors on met à jour dans la base de données*/
                else
                    begin
                        update pc
                        set pc_marque = @pc_marque, pc_modele = @pc_modele, pc_nomreseau = @pc_nomreseau, pc_versionos = @pc_versionos, pc_memoireram = @pc_memoireram, pc_memoirestockage = @pc_memoirestockage, pc_processeur = @pc_processeur, pc_prof = @pc_prof
                        where pc_mat = @pc_mat
                    end
            end
                    /* Si le materiel auquel on veut associer le type n'est pas créer alors on rollback*/
        else
            begin
                print 'le materiel nest pas prealablement enregistré'
                rollback transaction
            end
        /*On passe à l'insertion/ mise à jour suivante*/
        fetch next from BDPRO_CurseurPC into @pc_marque, @pc_modele, @pc_nomreseau, @pc_versionos, @pc_memoireram, @pc_memoirestockage, @pc_processeur, @pc_prof, @pc_mat

    end
/*on ferme le curseur*/
close BDPRO_CurseurPC
deallocate BDPRO_CurseurPC```

[enter image description here][1]


  [1]: https://i.stack.imgur.com/dwmDn.png
T_Gchet
  • 1
  • 1
  • This [answer](https://stackoverflow.com/questions/22015179/fatal-error-call-to-undefined-function-sqlsrv-connect) solve your problem? – Simone Rossaini Jan 16 '20 at 15:06
  • You can use stored procedures for all insert/update/delete. – jarlh Jan 16 '20 at 15:12
  • No, because i can see sqlsrv and pdo_sqlsrv in phpinfos() but in my php code, ```sqlserv_connect()``` still undefined. i'm using thread safety, with php 7.2 and dll is in 64 bits so i don't understand why it is not working – T_Gchet Jan 16 '20 at 15:12
  • i use trigger because it check if equipment is not already related or not created, and to know if it is an update or insert. Do you want to see my code ? – T_Gchet Jan 16 '20 at 15:15
  • is it possible you are using a different version of PHP? Maybe you have more than one version installed in the machine? In that case, you might not have the extension installed in that version. – ADyson Jan 16 '20 at 15:28
  • @ADyson yes when i click on wamp i see differents versions, but there are extensions. Edit: on the website i make, php version is 7.2.14 – T_Gchet Jan 16 '20 at 15:31
  • so all the versions of PHP on your machine have those extensions installed and activated, is that what you're saying? – ADyson Jan 16 '20 at 15:34
  • @ADyson when i change php version in wamp i see in extension panel that there are the same extension activated (for exemple : bz2, curl and more...) – T_Gchet Jan 16 '20 at 15:38
  • the file that i edit is PhpForApache.ini like describe in "configuration File (php.ini path" in phpinfo() – T_Gchet Jan 16 '20 at 15:52
  • Why are you using a cursor for a bunch of inserts? This can and should be simplified to two statements. First use an EXISTS to see if any rows violate your business rules. The do a single insert statement. This really need a complete rewrite into a set based process. – Sean Lange Jan 16 '20 at 16:32
  • You talk about ecran_mat imp_mat and vid_mat ? – T_Gchet Jan 16 '20 at 16:38
  • Also using print in a trigger is pointless outside of debugging. Not to mention you rollback the transaction inside a loop. If you encounter a second violation this will crash because there won't be a transaction to rollback. Yet another reason to make this set based. – Sean Lange Jan 16 '20 at 16:57
  • I know that it's possible that there are mistakes, i'm Always in studies. I will fix this. On another side donyou know how to replace instead of in MySQL ? – T_Gchet Jan 16 '20 at 17:02

0 Answers0